{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyboardInterrupt",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[6], line 19\u001b[0m\n\u001b[1;32m     17\u001b[0m         notes\u001b[38;5;241m.\u001b[39mappend(json_da[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcontent\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m     18\u001b[0m         notes\u001b[38;5;241m.\u001b[39mappend(json_da[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mnote\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[0;32m---> 19\u001b[0m         \u001b[43mtime\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m0.3\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m     20\u001b[0m     \u001b[38;5;28;01melse\u001b[39;00m:\u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m完了\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m     22\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m./txt/wordday.txt\u001b[39m\u001b[38;5;124m'\u001b[39m,\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mwb\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n",
      "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
     ]
    }
   ],
   "source": [
    "from ctypes import wintypes\n",
    "import datetime\n",
    "import time\n",
    "import requests,json\n",
    "\n",
    "\n",
    "url_temple = 'http://open.iciba.com/dsapi/?date='\n",
    "now = datetime.date.today()\n",
    "notes = []\n",
    "\n",
    "for i in range(1000):\n",
    "    if i <= 1000:\n",
    "        alter_day = now + datetime.timedelta(days=-i)\n",
    "        url = url_temple + str(alter_day)\n",
    "        res = requests.get(url).text\n",
    "        json_da = json.loads(res)\n",
    "        notes.append(json_da['content'])\n",
    "        notes.append(json_da['note'])\n",
    "        time.sleep(0.3)\n",
    "    else:print('完了')\n",
    "\n",
    "with open('./txt/wordday.txt','wb') as f:\n",
    "    for i,v in enumerate(notes):\n",
    "        if i%2==0:\n",
    "            f.write(notes[i]+'\\t')\n",
    "        else:f.write(notes[i+1]+'\\n')\n",
    "        \n",
    "\n",
    "            "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.8.10 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
